//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { scrollMixin } from "utils/mixin";
import studentItem from '../comm/studentItem.vue';
export default {
  name:'',
  mixins: [scrollMixin], //加载更多
  //import引入的组件需要注入到对象中才能使用
  components: {studentItem},
  data() {
  return {
    query:{
      student_keyword:'',
      page:1
    },
    totalPage:0,
    isLoadMore: true,
    searchValue:'',
    studentArr:[],
    iPnoneBottomBol: false, //是否是苹果手机
    coThemeColor:''
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    getiPnoneBottom() { //检测是否为苹果手机
      var userAgent = navigator.userAgent;
      var isiOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
      isiOS?this.iPnoneBottomBol = true:this.iPnoneBottomBol = false;
    },
    colorFin(a) { //处理主题色
      a = a.substring(1);
      a = a.toLowerCase();
      let b = new Array();
      for (let x = 0; x < 3; x++) {
        b[0] = a.substr(x * 2, 2);
        b[3] = "0123456789abcdef";
        b[1] = b[0].substr(0, 1);
        b[2] = b[0].substr(1, 1);
        b[20 + x] = b[3].indexOf(b[1]) * 16 + b[3].indexOf(b[2]);
      }
      return b[20] + "," + b[21] + "," + b[22];
    },
    studentDel(id) {
      console.log(id);
      this.$dialog.confirm({
        // title: '标题',
        message: '是否确定删除该学员？',
      })
        .then(() => {
          // on confirm
          $http.post("plugin.event-registration.api.student.delete", {id:id}, "正在获取").then(
            response => {
              if (response.result == 1) {
                let res = response.data;
                console.log(res);
                this.$toast(response.msg);
                this.query.page = 1;
                this.goodsList();
              } else {
                
                this.$dialog.alert({ message: response.msg });
              }
            },
            function(response) {
              // console.log(response);
              // error callback
            }
          );
        })
        .catch(() => {
          // on cancel
        });
    },
    onSearch() {
      this.query.page = 1;
      this.studentArr = [];
      this.goodsList();

    },
    studentTo() {
      this.$router.push(this.fun.getUrl("actionStudent", {}, {}));
    },
    goodsList() {
      $http.get("plugin.event-registration.api.student.get-list", this.query, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            this.isLoadMore = true;
            this.totalPage = res.last_page;
            if (!this.totalPage) {
              this.query.page = 0;
            }
            this.studentArr = res.data;
          } else {
            this.query.page = this.query.page - 1;
            this.isLoadMore = false;
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.query.page >= this.totalPage) {
        return;
      } else {
        this.query.page  = this.query.page+1;
        $http.get("plugin.event-registration.api.student.get-list", this.query, "正在获取").then(
          response => {
            if (response.result == 1) {
              let res = response.data;
              let list = res.data;
              this.isLoadMore = true;
              this.studentArr = [...this.studentArr, ...list];
            } else {
              this.query.page = this.query.page - 1;
              this.isLoadMore = false;
              this.$dialog.alert({ message: response.msg });
            }
          },
          function(response) {
            // console.log(response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.query.student_keyword = '';
    this.query.page = 1;
    this.studentArr = [];
    let themeColor = JSON.parse(localStorage.getItem("yz_basic_info")).theme_color || "";
    console.log(themeColor);
    this.coThemeColor = this.colorFin(themeColor) || this.colorFin('#F15353');
    this.getiPnoneBottom();
    this.goodsList();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
}